package com.xique.door.controller;


import com.xique.common.core.utils.SecurityUtils;
import com.xique.common.core.utils.poi.ExcelUtil;
import com.xique.common.core.web.controller.BaseController;
import com.xique.common.core.web.domain.AjaxResult;
import com.xique.common.core.web.page.TableDataInfo;
import com.xique.common.log.annotation.Log;
import com.xique.common.log.enums.BusinessType;
import com.xique.common.security.annotation.PreAuthorize;
import com.xique.door.bean.domain.VerifyRecords;
import com.xique.door.bean.request.VerifyRecordsRequest;
import com.xique.door.service.IVerifyRecordsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 一体机识别记录Controller
 *
 * @author caogq
 * @date 2021-06-22
 */
@Controller
@RequestMapping("/verify/records")
public class VerifyRecordsController extends BaseController {
    private String prefix = "oms/verifyRecords";

    @Autowired
    private IVerifyRecordsService verifyRecordsService;


    /**
     * 查询一体机识别记录列表
     */
    @PreAuthorize(hasPermi = "door:records:list")
    @GetMapping("/list")
    @ResponseBody
    public TableDataInfo list(VerifyRecordsRequest verifyRecordsRequest) {
        verifyRecordsRequest.setParkId(SecurityUtils.getParkId());
        startPage();
        List<VerifyRecords> list = verifyRecordsService.searchVerifyRecordsList(verifyRecordsRequest);
        return getDataTable(list);
    }

    /**
     * 导出一体机识别记录列表
     */
    @PreAuthorize(hasPermi = "door:records:export")
    @PostMapping("/export")
    @ResponseBody
    public void export(HttpServletResponse response, VerifyRecords verifyRecords) throws IOException {
        List<VerifyRecords> list = verifyRecordsService.selectVerifyRecordsList(verifyRecords);
        ExcelUtil<VerifyRecords> util = new ExcelUtil<VerifyRecords>(VerifyRecords.class);
        util.exportExcel(response, list, "records");
    }


    /**
     * 新增保存一体机识别记录
     */
    @PreAuthorize(hasPermi = "door:records:add")
    @Log(title = "一体机识别记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(VerifyRecords verifyRecords) {
        verifyRecords.setRemark("一体机识别记录add");
        return toAjax(verifyRecordsService.insertVerifyRecords(verifyRecords));
    }

    /**
     * 修改一体机识别记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        VerifyRecords verifyRecords = verifyRecordsService.selectVerifyRecordsById(id);
        mmap.put("verifyRecords", verifyRecords);
        return prefix + "/edit";
    }

    /**
     * 修改保存一体机识别记录
     */
    @PreAuthorize(hasPermi = "door:records:edit")
    @Log(title = "一体机识别记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(VerifyRecords verifyRecords) {
        return toAjax(verifyRecordsService.updateVerifyRecords(verifyRecords));
    }

    /**
     * 删除一体机识别记录
     */
    @PreAuthorize(hasPermi = "door:records:remove")
    @Log(title = "一体机识别记录", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(verifyRecordsService.deleteVerifyRecordsByIds(ids));
    }
}
